(function($, doc) {
	$.init();
	$.plusReady(function() {
		mui("#findhrefs").on("tap", "a", function() {

			var targets = this.getAttribute("href");
			if(this.getAttribute("href") == 'pages/friends/profile.html') {
				mui.openWindow({
					url: "pages/friends/profile.html",
					id: "pages/friends/profile.html",
					extras: {
						u_id: app.getState().user_id,
						head_img: app.getState().avatar,
						name: app.getState().name
					}
				});
			} else if(this.getAttribute("href") == 'http://www.dp.tc') {
				plus.runtime.openURL('https://www.dp.tc/Login/index.html');
			} else if(this.getAttribute("href") == 'https://www.fatcatbet.net/') {
				plus.nativeUI.alert('开发中！');
				//plus.runtime.openURL('https://www.fatcatbet.net/');
			} else if(this.getAttribute("href") == 'pages/find/weep.html') {
				plus.webview.open(targets,'weep');
				//plus.webview.show('weep');
				/*
				var server_url = plus.webview.getWebviewById('weep');
				if(server_url) {
					plus.webview.show(server_url);
				} else {
					plus.webview.create(targets,'weep');
					plus.webview.show(server_url);
				}*/

			} else if(this.getAttribute("href") == '#') {
				plus.nativeUI.alert('开发中！');
			}
			//plus.runtime.openURL
			else {
				//location.href = targets;
				var service_comfirm = plus.webview.getWebviewById(targets);
				service_comfirm && plus.webview.close(service_comfirm, "none");
				mui.openWindow({
					url: targets,
					id: targets
				})
			}

			/*
			mui.openWindow({
				url: targets,
				id: targets
			});*/
		});
		var mainid = localStorage.getItem('mainpage');
		var mainWin = plus.webview.getWebviewById(mainid);
		doc.addEventListener('swipeleft', function(event) {
			var angle = event.detail.angle;
			angle = Math.abs(angle);
			if(angle > 165 && angle < 195) {
				mui.fire(mainWin, 'swipe_event', {
					target: 'me.html'
				});
			}
		});
		doc.addEventListener('swiperight', function(event) {
			if(Math.abs(event.detail.angle) < 30) {
				mui.fire(mainWin, 'swipe_event', {
					target: 'contact.html'
				});
			}
		});
		
	});

}(mui, document));